﻿using Mono.Cecil;

namespace il2lua.TypeSystem;

public class ILType : Role, IType
{
    private readonly IDictionary<string, int> _repeats;
    public ILType(string name, INameSpace parent)
        : base(name, parent, ObjectKind.Object)
    {
        _repeats = new Dictionary<string, int>();
        Methods = new List<IMethod>();
        Fields = new List<IField>();
    }
    public IList<IMethod> Methods { get; private set; }
    public IList<IField> Fields { get; private set; }
    public TypeDefinition TypeDefinition { get; set; }
    public TypeReference TypedReference { get; set; }
    public string RenameMethod(string name)
    {
        if (_repeats.TryGetValue(name, out var index))
        {
            _repeats[name] = ++index;
            return $"{name}_r{index}";
        }
        _repeats[name] = 0;
        return name;
    }
}
